package com.twu.biblioteca.ui.menus.users;

import com.google.common.base.Optional;
import com.twu.biblioteca.library.Library;
import com.twu.biblioteca.ui.menus.AbstractMenu;
import com.twu.biblioteca.users.User;

/**
 * @author Alvi Jonathan Sait
 */
public class PasswordMenu extends AbstractMenu {

    private final String username;

    public PasswordMenu(Library library, String username) {
        super(library);
        this.username = username;
    }

    @Override
    public String getOutput() {
        return "Please enter your credentials";
    }

    @Override
    public String getUserPrompt() {
        return "Please enter your password";
    }

    @Override
    public AbstractMenu handleInput(String password) {
        Optional<User> loginUser = getLibrary().getUserAccountsManager().authenticateUser(username, password);
        if (loginUser.isPresent()) {
            return new SuccessfulLoginMenu(getLibrary());
        }
        return new UnsuccessfulLoginMenu(getLibrary());
    }
}
